﻿@using Microsoft.AspNetCore.Authentication
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
    <script type="text/javascript" src="~/scripts/jquery-3.4.1.js"></script>
    <script type="text/javascript">
    $(document).ready(init);

    function init() {
        $("select[name='ddlCurrentUserRoles']").change(function () {
            var selectedValue = $(this).val();
            ShowCurrentUserPermission(selectedValue);
        });
    }

        function ShowCurrentUserPermission(val) {
            $.ajax({
                url: "@Url.Action("ShowCurrentUserPermission", "Home")",
                data: { roleassignmentid: val },
                success: function (data) {
                    $("#divCurrentUserPermisson").html(JSON.stringify(data));
                }
            });
        }


        function GetUserMenus() {
            $.ajax({
                url: "@Url.Action("GetUserMenus", "Home")",
                success: function (data) {
                    $("#userMenus").html(JSON.stringify(data));
                }
            });
        }

        function GetApiClaims() {
        $.ajax({
            url: "@Url.Action("GetApiClaims", "Home")",
            success: function (data) {
                $("#apiClaims").html(JSON.stringify(data));
            }
        });
    }
    </script>
</head>
<body>
    <h3 align="center">This is a Microservice Demo.</h3>
    @if (!User.Identity.IsAuthenticated)
    {
        <h3>Error! User Is not Authenticated.</h3>
    }
    

    <h2>HostWeb Claims</h2>
    <dl>
        @foreach (var claim in User.Claims)
        {
            <dt>@claim.Type</dt>
            <dd>@claim.Value</dd>
        }
    </dl>
    "API AccessToken: Bearer @ViewData["APIAccessToken"]
    <br />
    Current User Roles：@Html.DropDownList("ddlCurrentUserRoles","-- select --")
    <br />
    Current User Permissions：
    <div id="divCurrentUserPermisson"></div>
    <br />

    <div>
         User Menus: <a href="#" onclick="GetUserMenus()">GetUserMenus</a>
        <div id="userMenus"></div>
        <br />
        API Claims: <a href="#" onclick="GetApiClaims()">GetApiClaims</a>
        <div id="apiClaims"></div>
        <br />
        <a href="/Home/Logout">Logout</a>
        <br />

    </div>

</body>


</html>
